//
//  MoreCourseTableViewCell.m
//  TeacherNet
//
//  Created by slz on 2017/11/9.
//  Copyright © 2017年 bnsr. All rights reserved.
//

#import "MoreCourseTableViewCell.h"

@implementation MoreCourseTableViewCell
{
    CourseTypeListModel * _leftModel;
    CourseTypeListModel * _rightModel;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        CGFloat labelMaxWidth = (kScreenWidth - 100) * .5;
        _leftLabel = [UILabel new];
        _leftLabel.userInteractionEnabled = YES;
        [_leftLabel addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(leftTap)]];
        _leftLabel.fontSize = 15;
        _leftLabel.textColor = kLight_TextColor_Default;
        _leftLabel.origin = CGPointMake(45, 0);
        _leftLabel.size = CGSizeMake(labelMaxWidth, 50);
        [self.contentView addSubview:_leftLabel];
        
        _rightLabel  =[UILabel new];
        _rightLabel.fontSize = 15;
        _rightLabel.userInteractionEnabled = YES;
        [_rightLabel addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(rightTap)]];
        _rightLabel.origin = CGPointMake(55 + labelMaxWidth, 0);
        _rightLabel.size = CGSizeMake(labelMaxWidth, 50);
        _rightLabel.textColor = kLight_TextColor_Default;
        [self.contentView addSubview:_rightLabel];
        
        CALayer * lineLayer = [CALayer new];
        lineLayer.backgroundColor = kLineColor_Gray_Default.CGColor;
        [self.contentView.layer addSublayer:lineLayer];
        
        lineLayer.frame = CGRectMake(0, 0, kScreenWidth, 1);
    }
    return self;
}

- (void)leftTap{
    if ([self.delegate respondsToSelector:@selector(cellClickWithModelId:)]){
        [self.delegate cellClickWithModelId:_leftModel.courseTypeId];
    }
}

- (void)rightTap{
    if ([self.delegate respondsToSelector:@selector(cellClickWithModelId:)]){
        [self.delegate cellClickWithModelId:_rightModel.courseTypeId];
    }
}

-(void)setWithLeftModel:(CourseTypeListModel *)model rightModel:(CourseTypeListModel *)rightModel{
    _leftModel = model;
    _rightModel = rightModel;
    if (model == nil){
        _leftLabel.hidden = YES;
    }else{
        _leftLabel.hidden = NO;
        _leftLabel.text = model.courseTypeName;
    }
    
    if (rightModel == nil){
        _rightLabel.hidden = YES;
    }else{
        _rightLabel.hidden = NO;
        _rightLabel.text = rightModel.courseTypeName;
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
